package com.fastloan.mgt.application.contract.controller;

import com.fastloan.common.model.CheckResult;
import com.fastloan.mgt.application.contract.service.CustomerContractService;
import com.kawins.result.ResultEnum;
import com.kawins.result.ResultTo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author yanwe
 * createTime 2017-12-2017/12/20 17:54
 */
@RestController
@RequestMapping("/api/customer/contract")
public class CustomerContractController {

    @Autowired
    private CustomerContractService customerContractService;

    @GetMapping("/{applicationId}")
    public ResultTo getContractInfo(@PathVariable("applicationId") String applicationId){
        return new ResultTo().setData(customerContractService.getCustomerContractInfo(applicationId));
    }


    @GetMapping("/sign/{applicationId}")
    public ResultTo agreeContract(@PathVariable("applicationId") String applicationId
            , @RequestParam(value = "agree") boolean agree) {
        CheckResult checkResult = customerContractService.agreeContract(applicationId,agree);
        if (!checkResult.isCheckResult()){
            return new ResultTo(ResultEnum.OPERATION_FAILED,checkResult.getCheckMsg());
        }
        return new ResultTo();
    }
}
